#include <QObject>
#include <QWidget>

#include "_Interface/_Datastruct.h"
#include "_Interface/_interface_backend.h"
#include "_Interface/_interface_hmi.h"

#include "Hmi/cCoordinateAdjust/coordinateadjust.h"
#include "ui_coordinate_adjust_hmi.h"

DialogCoordinateAdjust::DialogCoordinateAdjust(){

    ui = new Ui::CoordinateAdjustHMI;
    this->ui->setupUi(this);

    connect(ui->btnApple, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_Apply()));
    connect(ui->btnCancel, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_Cancel()));
    connect(ui->rbtnJOINT, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_Joint()));
    connect(ui->rbtnWORLD, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_World()));
    connect(ui->rbtnWORK, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_Work()));
    connect(ui->rbtnTOOL, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_Tool()));

}
DialogCoordinateAdjust::~DialogCoordinateAdjust(){
    if(ui != nullptr) delete ui;
}

void DialogCoordinateAdjust::setHandle(BackendInterface* pB){
    this->pBackend = pB;

    this->ui->ToolNum->setValue(pBackend->stOperationInfo.ToolNumber);
    this->ui->WorkNum->setValue(pBackend->stOperationInfo.WorkNumber);

    if(pBackend->stOperationInfo.MotionCoordinate == 0) this->ui->rbtnJOINT->setChecked(true);
    if(pBackend->stOperationInfo.MotionCoordinate == 1) this->ui->rbtnWORLD->setChecked(true);
    if(pBackend->stOperationInfo.MotionCoordinate == 2) this->ui->rbtnWORK->setChecked(true);
    if(pBackend->stOperationInfo.MotionCoordinate == 4) this->ui->rbtnTOOL->setChecked(true);

}

void DialogCoordinateAdjust::onbtnclicked_Apply(){
    if(this->pBackend != nullptr){
        pBackend->stOperationInfo.ToolNumber = this->ui->ToolNum->value();
        pBackend->stOperationInfo.WorkNumber = this->ui->WorkNum->value();
        this->close();
    }
    this->close();
}
void DialogCoordinateAdjust::onbtnclicked_Cancel(){
    this->close();
}
void DialogCoordinateAdjust::onbtnclicked_Joint(){
    if(this->pBackend != nullptr){
        pBackend->stOperationInfo.MotionCoordinate = 0;
    }
}
void DialogCoordinateAdjust::onbtnclicked_World(){
    if(this->pBackend != nullptr){
        pBackend->stOperationInfo.MotionCoordinate = 1;
    }
}
void DialogCoordinateAdjust::onbtnclicked_Work(){
    if(this->pBackend != nullptr){
        pBackend->stOperationInfo.MotionCoordinate = 2;
    }
}
void DialogCoordinateAdjust::onbtnclicked_Tool(){
    if(this->pBackend != nullptr){
        pBackend->stOperationInfo.MotionCoordinate = 3;
    }
}
